﻿@model HMoPro.Models.EditResourceFirstPart

@{
    ViewBag.Title = "EditResourceFirstPart";
}
@section Scripts {

    @Scripts.Render("~/bundles/zTree_v3")
}
     @Styles.Render("~/zTree_v3/css")

<script type="text/javascript">

        var treeid;
        var treename;
        var resource_category_id;
        $(document).ready(function () {
            $.ajax({
                type: "Get",
                url: "@Url.Action("getmenu","Category")",
                async: false,
                cache:false,
                success: function (data) {
                    tree=$.fn.zTree.init($("#treeDemo"), setting, data);
                    tree.expandAll(true);
                }
            });
        })
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
                callback: {
                    onClick: zTreeOnClick
                }
            };

        function zTreeOnClick(event, treeId, treeNode) {
            treeid = treeNode.id;
            treename = treeNode.name;
                 
        }



    </script>
 <script >
     function deletecategory(obj) {
         resource_category_id = obj.id;
         // this.style.color = "red";
         //   $("#categorylist").remove(obj.id);
     }


     //变量名中多了空格，倒置调试了半天
        $(function () {
            $('button#cancel').bind("click", function () {
                $.ajax({
                    url: "@Url.Action("Edit_deleteCategory")",
                    data: { "resource_category_id": resource_category_id, "resourceid": '@ViewData["resourceid"]' },
                dataType: "json",
                 type: "POST",
                 success: function (data) {
                     // your logic  
                     resource_category_id = null;
                     var nodestring = "";
                     for (var i=0; i < data.categorydata.length; i++) {
                         var node = "<a href=" + "#" + " id=" + "\"" + data.categorydata[i].resource_category_id + "\"" + "onclick=" + "\"" + "deletecategory(this);return false;" + "\"" + ">" + data.categorydata[i].categoryname + "</a><br>"
                         nodestring += node;
                     }
                     document.getElementById("categorylist").innerHTML = nodestring;
                       
                        
              }
            });


            })


            $('button#add2').bind("click", function () {
                $.ajax({
                    url: "@Url.Action("Edit_AddCategory")",
                    data: { "category_id": treeid, "resourceid": '@ViewData["resourceid"]' },
                    dataType: "json",
                    type: "POST",
                    success: function (data) {
                        // your logic  
                        var nodestring = "";
                        for (var i = 0; i < data.categorydata.length; i++) {
                            var node = "<a href=" + "#" + " id=" + "\"" + data.categorydata[i].resource_category_id + "\"" + "onclick=" + "\"" + "deletecategory(this);return false;" + "\"" + ">" + data.categorydata[i].categoryname + "</a><br>"
                            nodestring += node;
                        }
                        document.getElementById("categorylist").innerHTML = nodestring;


                    }
                });


                        })




              }
            )

    </script>
<style>
    body, h1, h2, h3, h4, h5, h6, small, .button {
        font-family: "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif !important;
    }
    h3, .h3 {
        font-size: 24px;
    }

    h1, .h1, h2, .h2, h3, .h3 {
        margin-top: 20px;
        margin-bottom: 10px;
    }

    h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
        font-family: inherit;
        font-weight: 500;
        line-height: 1.1;
        color: inherit;
    }

    .form-horizontal .control-label {
        padding-top:3px;
    }
    .form-horizontal .text-box {
        width:300px;
        padding-left:3px;
    }
    #categorylist a {
        display:inline-block;
        margin-top:2px;
        padding-top:1px;
        text-decoration:none;
    }
    #categorylist a:hover {
        text-decoration: underline;
    }
</style>

<div id="main">
    <h3>编辑资源 - STEP 1</h3>

    @using (Html.BeginForm("EditResourceFirstPart", "Resource", FormMethod.Post, new { @role = "form", @class = "form-horizontal" }))
    {
        @Html.ValidationSummary(true)
        <div class="form-group">
            <div class="col-xs-2 control-label">
                @Html.LabelFor(model => model.title)
            </div>
            <div class="col-xs-10">
                @Html.EditorFor(model => model.title, new { @class = "form-control" })
            </div>
            <div class="col-xs-offset-2 col-xs-10 text-danger">
                @Html.ValidationMessageFor(model => model.title)
            </div>
        </div>

        <div class="form-group">
            <div class="col-xs-2 control-label">
                @Html.LabelFor(model => model.subtitle)
            </div>
            <div class="col-xs-10">
                @Html.EditorFor(model => model.subtitle, new { @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-2 control-label">
                @Html.LabelFor(model => model.describe)
            </div>
            <div class="col-xs-10">
                @Html.EditorFor(model => model.describe, new { @class = "form-control" })
            </div>
            <div class="col-xs-offset-2 col-xs-10 text-danger">
                @Html.ValidationMessageFor(model => model.describe)
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-2 control-label">
                @Html.LabelFor(model => model.location)
            </div>
            <div class="col-xs-10">
                @Html.EditorFor(model => model.location, new { @class = "form-control" })
            </div>
            <div class="col-xs-offset-2 col-xs-10 text-danger">
                @Html.ValidationMessageFor(model => model.location)
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-2 control-label">
                类别
            </div>
            <div class="col-xs-3">
                <div id="categorylist">

                    @foreach (var item in Model.editcategorylist)
                    {
                        <a href="#" id="@item.resource_category_id" onclick="deletecategory(this);return false;">@item.categoryname</a><br />
                    }
                </div>
            </div>
            <div class="col-xs-1" style="padding-top:120px;">
                <p style="margin-bottom:10px;"><button type="button" id="add2" class="button button-plain button-highlight button-small"><<</button></p>
                <p><button type="button" id="cancel" class="button button-small">>></button></p>
            </div>
            <div class="col-xs-4 col-xs-offset-1">
                <ul id="treeDemo" class="ztree" style="width:100%"></ul>
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-offset-2 col-xs-10">
                @Html.Hidden("resourceid", ViewData["resourceid"])
                <input type="submit" value="下一步" class="button button-raised button-caution button-pill" />
            </div>
        </div>


        @*<div class="editor-label">

            </div>
            <div>
                <div>
                </div>

                <div>
                    <ul id="treeDemo" class="ztree"></ul>
                </div>

            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.location)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.location)
                @Html.ValidationMessageFor(model => model.location)
            </div>
            <p>
                <input type="submit" value="下一步" />
            </p>*@
    }
</div>

<script>
    $("#carousel-hm").css("display", "none");
    $("#f2 a").html("<font> " + $("#f2 a").text() + " </font>")
    $("#f2 a").addClass("selected");
</script>